package com.xiaoshuidi.cloud.module.finance.service.finance.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaoshuidi.cloud.module.finance.dal.dataobject.finance.FinanceDivideAccountDo;
import com.xiaoshuidi.cloud.module.finance.dal.mysql.finance.FinanceDivideAccountMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @BelongsProject: lease-module-finance
 * @BelongsPackage: com.xiaoshuidi.cloud.module.finance.service.finance.impl
 * @Author: James
 * @CreateTime: 2023-12-05  17:19
 * @Description: TODO
 * @Version: 1.0
 */
@Component
@RequiredArgsConstructor
public class FinanceDivideitory extends ServiceImpl<FinanceDivideAccountMapper,FinanceDivideAccountDo>  {

    private final FinanceDivideAccountMapper financeDivideAccountMapper;


    public List<FinanceDivideAccountDo> getFinanceDivideAccount(Long apartmentId) {
        LambdaQueryWrapper<FinanceDivideAccountDo> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(FinanceDivideAccountDo::getApartmentId,apartmentId);
        return financeDivideAccountMapper.selectList(wrapper);
    }

    public void insertFinanceDivide(List<FinanceDivideAccountDo> financeDivideAccountDo) {
        financeDivideAccountMapper.insertBatch(financeDivideAccountDo);
    }

    public void updateDivideAccount(List<FinanceDivideAccountDo> financeDivideAccountDo) {
        for (FinanceDivideAccountDo financeDivideAccount:financeDivideAccountDo) {
            if(null==financeDivideAccount.getId()||"".equals(String.valueOf(financeDivideAccount.getId()))){
                financeDivideAccountMapper.insert(financeDivideAccount);
            }else{
                financeDivideAccountMapper.updateById(financeDivideAccount);
            }
        }
    }
}
